using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;

public partial class installer : System.Web.UI.Page
{
	protected void Page_Load(object sender, EventArgs e)
	{
		StringBuilder messages = new StringBuilder("Installer Status <br>");

	 	if (Roles.RoleExists("Database Owner") == false)
		{
			Roles.CreateRole("Database Owner");
			messages.Append("Role: <b>Database Owner</b> Created<br>");
		}

		if (Roles.RoleExists("Database Administrator") == false)
		{ 
			Roles.CreateRole("Database Administrator");
            messages.Append("Role: <b>Database Administrator</b> Created<br>");
		}

		if (Roles.RoleExists("Membership Administrator") == false)
		{ 
			Roles.CreateRole("Membership Administrator");
			messages.Append("Role: <b>Membership Administrator</b> Created<br>");		
		}

		if (Roles.RoleExists("Membership User") == false)
		{ 
			Roles.CreateRole("Membership User");
			messages.Append("Role: <b>Membership User</b> Created<br>");				
		}

		if (Membership.FindUsersByName("Admin").Count < 1)
		{
			MembershipCreateStatus mstatus;
			Membership.CreateUser("Admin", "1.admin.1", "sqltools@telligent.com", "What is the Matrix", "it is around us", true, out mstatus);
			messages.Append("User: <b>Admin</b> Created.  Login User/Pass is Admin/1.admin.1 <br>");				
		}

		Roles.AddUserToRole("Admin", "Membership Administrator");

		messages.Append("<b>Admin</b> added to Membership Administrator Role<br />");
        messages.Append("<br />The Installer has created the required roles and admin user for the Sql Server Web Tools application.  You may delete the installation files (Installer.aspx and Installer.aspx.cs)");
		InstallerStatus.Text = messages.ToString();
	}
}
